#include <iostream>
#include <cstdlib>
#include <streambuf>
#include <ostream>
#include "CReadStream.h"
using namespace std;
int_type CReadBuf::overflow(int_type c)
{
	int num = pptr() - pbase();
	flushBuf();
	pbump( -num);
	if(num)
	{
		*pptr() = c;
		pbump(1);
	}
	return c;
}
streamsize CReadBuf::xsputn(const char *s, streamsize n)
{
	streamsize len = n;
	int count = 0;
	while(len > 0)
	{
		if(count == mBufSize)
			count = 0;
		sputc(s[n - len]);
		len--;
		count++;
	}
	cout<<"xsputn"<<endl;
	return n;
}
void CReadBuf::flushBuf()
{
	int n = pptr() - pbase();
	if(n > 0)
		write(mFd, mBuf, n);
}
int CReadBuf::sync()
{
	cout<<"sync()"<<endl;
	flushBuf();
	return 0;
}
